//
//  HomeSectionViewCourseNotice.m
//  yjw-winner
//
//  Created by 隆霁 on 2018/9/25.
//  Copyright © 2018年 Shanghai decade financial information service co., LTD. All rights reserved.
//

#import "HomeSectionViewCourseNotice.h"
#import "Cell_HomeCourseNotice.h"


static NSString *identifier = @"cell_home_course_notice_identifier";
@interface HomeSectionViewCourseNotice ()<UITableViewDelegate, UITableViewDataSource> {}

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) UIView *footerView;
@property (nonatomic, copy) CallBackCourseListBlock block;
@property (nonatomic, strong) id model;
@end
@implementation HomeSectionViewCourseNotice
+ (HomeSectionViewCourseNotice *)headView {
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([HomeSectionViewCourseNotice class]) owner:self options:nil] lastObject];
}

- (void)refreshWithModel:(id)model CallBackBlock:(CallBackCourseListBlock)block {
    self.model = model;
    self.block = block;
}
- (UIView *)footerView {
    if (!_footerView) {
        _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44)];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(10, 2, [UIScreen mainScreen].bounds.size.width - 20, 40);
        button.layer.masksToBounds = YES;
        button.layer.cornerRadius = 4.0f;
        button.backgroundColor = MJRefreshColor(240, 240, 240);
        [button setTitle:@"查看商学院课程表" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:MJRefreshColor(250, 170, 90) forState:UIControlStateNormal];
        [button addTarget:self action:@selector(lookUpCourseListButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_footerView addSubview:button];
    }
    return _footerView;
}
-(void)awakeFromNib {
    [super awakeFromNib];
    self.tableView.tableHeaderView = [UIView new];
    self.tableView.tableFooterView = self.footerView;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([Cell_HomeCourseNotice class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:identifier];
}

- (instancetype)init {
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil] lastObject];
}


#pragma mark --mark UITableViewDelegate UITableViewDataSource

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    Cell_HomeCourseNotice *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    if (!cell) {
        cell = [[Cell_HomeCourseNotice alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [MBProgressHUD showSuccess:[NSString stringWithFormat:@"did selected %lu, %lu", indexPath.section, indexPath.row]];
}

#pragma mark --mark EVENT

- (IBAction)signUpButtonClick:(UIButton *)sender {
    
    [MBProgressHUD showSuccess:@"我要报名"];
    
}

/**
 查看商学院课程列表

 @param sender sender
 */
- (void)lookUpCourseListButtonClick:(UIButton *)sender {
    if (self.block) {
        self.block();
    }
}
@end
